#include "Mydefine.h"



void USART1_IRQHandler()
{
	if(RESET != USART_GetITStatus(USART1, USART_IT_RXNE)){
		TIM_SetCounter(TIM3, 0);
		if(0 == (Buffer_flg1 & 0x8000)){
			Rcv_buffer1[Buffer_flg1++ & 0x7FFF] = USART_ReceiveData(USART1);
		}else{
			if(BUFFERSIZE < (Buffer_flg1&0x7FFF)){
				USART_ReceiveData(USART1);
			}else{
				Rcv_buffer1[Buffer_flg1 & 0x7FFF] = USART_ReceiveData(USART1);
			}
		}
	}
}



void USART2_IRQHandler()
{
	if(RESET != USART_GetITStatus(USART2, USART_IT_RXNE)){
		TIM_SetCounter(TIM3, 0);
		if(0 == (Buffer_flg2 & 0x8000)){
			Rcv_buffer2[Buffer_flg2++ & 0x7FFF] = USART_ReceiveData(USART2);
		}else{
			if(BUFFERSIZE <= (Buffer_flg2&0x7FFF)){
				USART_ReceiveData(USART2);
			}else{
				Rcv_buffer2[Buffer_flg2 & 0x7FFF] = USART_ReceiveData(USART2);
			}
		}
	}
}



void USART3_IRQHandler()
{
	if(RESET != USART_GetITStatus(USART3, USART_IT_RXNE)){
		TIM_SetCounter(TIM3, 0);
		if(0 == (Buffer_flg3 & 0x8000)){
			Rcv_buffer3[Buffer_flg3++ & 0x7FFF] = USART_ReceiveData(USART3);
		}else{
			if(BUFFERSIZE <= (Buffer_flg3&0x7FFF)){
				USART_ReceiveData(USART3);
			}else{
				Rcv_buffer3[Buffer_flg3 & 0x7FFF] = USART_ReceiveData(USART3);
			}
		}
	}
}



void TIM3_IRQHandler()
{
	if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET){
		if(0 != (Buffer_flg1 & 0x7FFF)){
			Buffer_flg1 |= 0x8000;
		}
		if(0 != (Buffer_flg2 & 0x7FFF)){
			Buffer_flg2 |= 0x8000;
		}
		if(0 != (Buffer_flg3 & 0x7FFF)){
			Buffer_flg3 |= 0x8000;
		}
		TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
		COUNTER > 100? COUNTER = 0: ++COUNTER;
	}
}


